package cn.jsj.dao;

import java.util.List;
import java.util.ListIterator;

/**
 * 备忘录信息操作类
 * @author LI
 *
 */
public class TblUpdateMemorandumDAO {


	/**
	 * 保存或者修改备忘录信息
	 * @param tm：备忘录信息类
	 * @return 1：保存成功
	 */
	public int saveOrUpdateMemorandum(cn.jsj.pojo.TblMemorandum tm){
		org.hibernate.Session session = HBUtils.getSession();
		// 新建事务对象
		org.hibernate.Transaction tx = session.beginTransaction();
		// 开始事务
		tx.begin();
		session.saveOrUpdate(tm);
		// 提交事务
		tx.commit();
		session.close();
		return 1;
	}

	public String todayTaskLook(){

		org.hibernate.Session session = HBUtils.getSession();
		// 新建事务对象
		org.hibernate.Transaction tx = session.beginTransaction();
		// 开始事务
		tx.begin();
		//获得今天是星期几
		int week=cn.jsj.utils.TimeDispose.getWeek();
		String weekString="sunday";
		if(week==1){
			weekString="sunday";
		}
		if(week==2){
			weekString="monday";
		}
		if(week==3){
			weekString="tuesday";
		}
		if(week==4){
			weekString="wednesday";
		}
		if(week==5){
			weekString="thursday";
		}
		if(week==6){
			weekString="friday";
		}
		if(week==7){
			weekString="saturday";
		}

		String hql="select "+weekString+" from TblMemorandum where memo_id=1";
		List result=session.createQuery(hql).list();

		// 提交事务
		tx.commit();
		session.close();
		//获得结果的迭代器
		 ListIterator iterator = result.listIterator();
		 //结果字符串
		 String resultString="";
		 while(iterator.hasNext()){
			 resultString=(String)iterator.next();
		 }
		 //调试信息
		 cn.jsj.utils.SysLogger.PrintInfo(resultString);
		return resultString;
	}
}
